import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const statusData = [{ name:'待审核', value:'0' },{ name:'审核通过', value:'2' },{ name:'审核未通过', value:'3' }]
// ==================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		// 所有的搜索医院，项目用下拉带搜索 20211012 耿琰
		// 项目名称修改为文本框搜索，列表新增申请时间 20211130 耿琰
		forms : [
			{ label: '医院名称',		name: 'hosp_id', type: 'select', nameStr:'name'},
			{ label:'物价代码',		name: 'price_code' },
			// { label: '项目名称',		name: 'kind_id', type: 'select' },
			{ label:'项目名称',		name: 'item_name' },
			{ label:'审核状态',		name: 'status',	type: 'select', data:statusData },
		],
	}
	
	model = {}
	query = { type:'my' }
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 医院
			$fn.setRow(forms, 'hosp_id', await f.getCache({ api:'hospital' } ) )
			// 项目名称
			// $fn.setRow( forms, 'kind_id', await f.getCache({ api:'labkindselect' } ) )
			this.setState({ forms })
		})
	}
	// paging
	fetch = () => $fn.fetch.call(this,'qt-hospital-price-audit/index',{isIndex:true} )
	
	// 表单
	cols = [
		{ title: '医院名称', 			dataIndex: 'hosp_name', 		width:150 },
		{ title: '物价代码', 			dataIndex: 'price_code', 		width:100 },
		{ title: '关联物价', 			dataIndex: 'price_rel_codes', 	width:150 },
		{ title: '项目名称', 			dataIndex: 'item_name', 		width:150},
		{ title: '申请人', 				dataIndex: 'operator', 			...$fn.table.name },
		{ title: '审核人', 				dataIndex: 'checkuser', 		...$fn.table.name },
		{ title: '标准价格（元）', 		dataIndex: 'source_price', 		...$fn.table.num },
		{ title: '结算价格（元）', 		dataIndex: 'price', 			...$fn.table.num },
		{ title: '申请时间', 			dataIndex: 'created_at', 		...$fn.table.time },
		{ title: '审核时间', 			dataIndex: 'update_at', 		width:100 },
		{ title: '备注', 				dataIndex: 'remark', 			width:100 },
		{ title: '状态', 				dataIndex: 'status', 			...$fn.table.status, render:text =>$fn.getState(statusData,text) },
	]
	
	render(){
		return (
			<>
				<Page title='我的物价审核'>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { idStr:'id', isIndex:true, isInit: window.isInit }) }
				</Page>
			</>
		)
	}
}

export default Index